﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


namespace LiveProjectManager.DDD.Domains
{
    public class User : Base.Domain
    {
        // Constants.
        public const int EMAIL_MAXLENGTH = 255;
        public const int PASSWORD_MAXLENGTH = 128;
        public const int USERNAME_MAXLENGTH = 25;
        public const int FIRSTNAME_MAXLENGTH = 20;
        public const int LASTNAME_MAXLENGTH = 20;

        // Primary key of a user.
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long Id { get; set; }

        // The user username.
        [Required]
        [StringLength(USERNAME_MAXLENGTH)]
        public string UserName { get; set; }

        // The user email.
        [Required]
        [StringLength(EMAIL_MAXLENGTH)]
        public string Email { get; set; }

        // The user password.
        [Required]
        [StringLength(PASSWORD_MAXLENGTH)]
        public string Password { get; set; }

        // The user first name.
        [Required]
        [StringLength(FIRSTNAME_MAXLENGTH)]
        public string FirstName { get; set; }

        // The user last name.
        [Required]
        [StringLength(LASTNAME_MAXLENGTH)]
        public string LastName { get; set; }

        // Is the user a manager?
        [Required]
        public bool isManager { get; set; }

        // Creation date & time.
        public DateTime CreatedOn { get; set; }

        // The user posts.
        public virtual ICollection<Post> Posts { get; set; }
        
        // The user post comments.
        public virtual ICollection<PostComment> PostComments { get; set; }

        // The user tasks.
        public virtual ICollection<Task> Tasks { get; set; }

        // The user pulicated resources.
        public virtual ICollection<Resource> Resources { get; set; }


        override public Dictionary<string, object> toDict()
        {
            Dictionary<string, object> myDict = new Dictionary<string, object>();
            myDict.Add("Id", Id);
            myDict.Add("UserName", UserName);
            myDict.Add("Email", Email);
            myDict.Add("Password", Password);
            myDict.Add("FirstName", FirstName);
            myDict.Add("LastName", LastName);
            myDict.Add("isManager", isManager);
            myDict.Add("CreatedOn", CreatedOn);
            return myDict;
        }
    }
}